#include <TF3.h>
#include "CpSimMain.h"
#include "CpLog.h"

#include "CpSimpleGenerator.h"
#include "CpSimpleTransporter.h"
#include "CpSimulator.h"
#include "CpFunctions.h"
ClassImp(CpSimulator);

int main(int argc, const char *argv[])
{

	if (argc < 2) {
		Printf("Error : Run ./coldpig <number of particles>");
		return 1;
	}
	CpFunctions::Init();
//    Double_t x=0,y=-1.4,z=4.35;
   Double_t x=0,y=0,z=2.5;
   Double_t vx=0,vy=0,vz=1e-3;
   CpFunctions::PrintMagneticInfo(x,y,z);
   
   CpFunctions::SetType(CpFunctions::kReal);
//    CpFunctions::SetType(CpFunctions::kTest);



//    printf("1. %e\n",6*TMath::Pi()*CpFunctions::kBloodViscosity*CpFunctions::kParticleR*vz/CpFunctions::ParticleMass());
//    printf("2. %e\n",/*CpFunctions::Chi(x,y,z)/*/CpFunctions::kMuZero*4*TMath::Pi()/3*TMath::Power(CpFunctions::kParticleR,3)/CpFunctions::ParticleMass());
// //    printf("2. %e\n",CpFunctions::Chi(x,y,z)/CpFunctions::kMuZero*4*TMath::Pi()/3*TMath::Power(CpFunctions::kParticleR,3)/CpFunctions::ParticleMass());
//    printf("3. %e\n",CpFunctions::Chi(x,y,z));
//    x=1;y=-1;z=2.5;
//    printf("3. %e\n",/*4*TMath::Pi()*TMath::Power(CpFunctions::kParticleR,3)/*/CpFunctions::kMuZero);
// //    printf("3. %e\n",CpFunctions::kMuZero*CpFunctions::kChi/ ( 4*TMath::Pi() ));
// //    printf("4. %e\n",CpFunctions::kMuZero*CpFunctions::kChi/ ( 4*TMath::Pi() )*CpFunctions::ParticleMass());
//    return 0;
//    printf("4. %e\n",CpFunctions::fgMagForceX->Eval(2.265522e-18,-1.695591e-02,3.700000e-02*100));
//    printf("4. %e\n",CpFunctions::fgMagForceX->Eval(0,0,0.45));
//    return 0;
   // setting Super Bulhar constalnt
//    CpFunctions::kBulharConstant = 1e13;
//    CpFunctions::kBulharConstant = 1e12;
//    CpFunctions::kBulharConstant = 1e11;
//    CpFunctions::kBulharConstant = 5*1e10;

   TString argString=argv[1];
   Int_t numParticles = argString.Atoi();

   argString=argv[2];
   Double_t numR = 100;
   if (!argString.IsNull()) numR = argString.Atof();

   argString=argv[3];
   Double_t numVz = 0.5;
   if (!argString.IsNull()) numVz = argString.Atof();
   
   CpFunctions::kBloodVelX = 0.0;
   CpFunctions::kBloodVelY = 0.0;
   CpFunctions::kBloodVelZ = numVz*1e-3;
   CpFunctions::kParticleR = numR*1e-9;
   CpFunctions::kBulharConstant = 1e8;

   printf("Running with R=%e and Vz=%e\n",CpFunctions::kParticleR ,CpFunctions::kBloodVelZ);
   
   CpSimulator sim;

	sim.SetGenerator(new CpSimpleGenerator());
	sim.SetTransporter(new CpSimpleTransporter());
	
  sim.Run(numParticles);

//   sim.ShowEvent();

   printf("Done.\n");
	
   return 0;
}
